<template>
  <view class="tab-bar">
    <view v-for="(item,index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
      <image class="tab_img" :src="selected === index ? item.selectedIconPath : item.iconPath"></image>
      <view class="tab_text" :style="{color: selected === index ? selectedColor : color}">{{item.text}}</view>
    </view>
  </view>
</template>
<script>
	const app = getApp()
  export default {
    props: {
      selected: { // 当前选中的tab index
          type: Number,
          default: 0
      },
    },
    data() {
      return {
        color: "#333333",
        selectedColor: "#3466ff",
        list: [
		  {
		  		"iconPath": "../static/icon/icon/tabbar/team1.png",
		  		"selectedIconPath": "../static/icon/icon/tabbar/team2.png",
		  		"pagePath": "/pages/home/home",
		  		"text": "找队伍"
		  	},
		  	{
		  		"iconPath": "../static/icon/icon/tabbar/massge1.png",
		  		"selectedIconPath": "../static/icon/icon/tabbar/massge2.png",
		  		"pagePath": "/pages/news/news",
		  		"text": "消息"
		  	},
		  	{
		  		"iconPath": "../static/icon/icon/tabbar/my1.png",
		  		"selectedIconPath": "../static/icon/icon/tabbar/my2.png",
		  		"pagePath": "/pages/my/my",
		  		"text": "个人中心"
		  	}
        ]
      }
    },
	onReady() {
		if (app.globalData.user) {
			if(app.globalData.user.group_id == 3){
				this.list = [
				  {
						"iconPath": "../static/icon/icon/tabbar/team1.png",
						"selectedIconPath": "../static/icon/icon/tabbar/team2.png",
						"pagePath": "/pages/home/home",
						"text": "找项目"
					},
					{
						"iconPath": "../static/icon/icon/tabbar/massge1.png",
						"selectedIconPath": "../static/icon/icon/tabbar/massge2.png",
						"pagePath": "/pages/news/news",
						"text": "消息"
					},
					{
						"iconPath": "../static/icon/icon/tabbar/my1.png",
						"selectedIconPath": "../static/icon/icon/tabbar/my2.png",
						"pagePath": "/pages/my/my",
						"text": "个人中心"
					}
				]
			}
		} else {
			var _this = this
			
				if(app.globalData.user.group_id == 3){
					_this.list = [
					  {
							"iconPath": "../static/icon/icon/tabbar/team1.png",
							"selectedIconPath": "../static/icon/icon/tabbar/team2.png",
							"pagePath": "/pages/home/home",
							"text": "找项目"
						},
						{
							"iconPath": "../static/icon/icon/tabbar/massge1.png",
							"selectedIconPath": "../static/icon/icon/tabbar/massge2.png",
							"pagePath": "/pages/news/news",
							"text": "消息"
						},
						{
							"iconPath": "../static/icon/icon/tabbar/my1.png",
							"selectedIconPath": "../static/icon/icon/tabbar/my2.png",
							"pagePath": "/pages/my/my",
							"text": "个人中心"
						}
					]
				}
		}
	},
    methods: {
      switchTab(item, index) {
        console.log("item", item)
        console.log("index", index)
        let url = item.pagePath;
		
        uni.switchTab({
            url:url
        })
      }
    }
  }
</script>
<style lang="less">
  .tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100rpx;
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
    .tab-bar-item {
      flex: 1;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      .tab_img {
          width: 37rpx;
          height: 41rpx;
      }
      .tab_text {
          font-size: 20rpx;
          margin-top: 9rpx;
      }
    }
  }
</style>